<template>
  <view class="qa-container">
    <u-input v-model="q" clearable placeholder="请输入问题"></u-input>
    <view class="mt20">
      <u-button type="primary" @click="sub" :disabled="isWaiting"
        >问一问</u-button
      >
    </view>
    <view class="mt20">
      <text>{{ isWaiting ? "思考中，请稍等.." : a }}</text>
    </view>
  </view>
</template>

<script>
import apis from "../../apis/apis";
export default {
  data() {
    return {
      isWaiting: false,
      q: "",
      a: "",
    };
  },
  methods: {
    sub() {
      let q = this.q;
      console.log("q:", q);
      this.isWaiting = true;
      this.$http
        .get(apis.getAnswer, { q })
        .then((res) => {
          console.log("q.res:", res);
          this.a = res;
        })
        .finally(() => {
          this.isWaiting = false;
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.qa-container {
  padding: 40rpx;
}
</style>
